/**
* Created by apple on 2016/11/16.
*/

module.exports = function(sequelize, DataTypes) {
    var User = sequelize.define('user', {
        id: {
            type: DataTypes.INTEGER,
            allowNull: false,
            unique: true,
            primaryKey: true,
            autoIncrement: true
        },
        name: {
            type: DataTypes.STRING,
            allowNull: false
        },
        password: {
            type: DataTypes.STRING,
            allowNull: false
        },
        ID_TYPE: {
            type: DataTypes.ENUM,
            values: [1, 2, 3, 4, 5],
            defaultValue: 1
        },
        ID_Number: {
            type: DataTypes.STRING,
            allowNull: false
        },
        email: {
            type: DataTypes.STRING,
            validate: {
                isEmail: true
            }
        },
        telephoneNumber: {
            type: DataTypes.STRING
        },
        CreditRank: {
            type: DataTypes.INTEGER,
            allowNull: false,
            defaultValue: 5
        }
    }, {
        underscore: true,
        'timestamps': false,
        'createdAt': false,
        'updatedAt': false
    }, {
        classMethods: {
            associate: function (models) {
                User.hasMany(models.Appointment);
                User.hasMany(models.Payment);
            }
        }
    });

    return User;
};